package com.nowcoder.Offer.String;

import org.junit.Test;

/**
 * 替换空格
 */
public class replaceString {
    public String replaceSpace(StringBuffer str) {
        StringBuilder strb = new StringBuilder();
        for(char c : str.toString().toCharArray()){
            if(c == ' '){
                strb.append("%20");
            }else{
                strb.append(c);
            }
        }
        return strb.toString();
    }

    @Test
    public void test(){
        String str = "hello world happy";

        System.out.println(replaceSpace(new StringBuffer(str)));
    }
}
